package rpc.provider.consumer.provider;

import rpc.provider.consumer.RpcException;
import rpc.provider.consumer.SoaErrorEnum;
import rpc.provider.consumer.SoaResponse;
import rpc.provider.consumer.UserService;

import java.util.Random;

/**
 * @author: cuiyutian1
 * @date: 2021/9/4 13:11
 * @description:
 */
public class UserQueryProvider {
    private int SUCCESS = 100;

    public SoaResponse<String> userQuery() {
        UserService service = new UserService();
        SoaResponse<String> stringSoaResponse = new SoaResponse<String>();
        try {
            Random random = new Random(1);
            int nextInt = random.nextInt();
            String userQuery = service.userQuery(nextInt);
            stringSoaResponse.setData(userQuery);
            stringSoaResponse.setCode(SoaErrorEnum.SUCCESS);
        }catch (RpcException e){
            stringSoaResponse.setCode(SoaErrorEnum.SYSTEM_ERROR);
            stringSoaResponse.setErrorMsg(e.getMessage());
        }catch (Exception e){
            stringSoaResponse.setCode(SoaErrorEnum.SYSTEM_ERROR);
            stringSoaResponse.setDisplayMsg(SoaErrorEnum.SYSTEM_ERROR);
            stringSoaResponse.setErrorMsg(e.getMessage());
        }
        return stringSoaResponse;
    }
}
